// import com.alibaba.druid.sql.ast.*;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.Arrays;
// import java.util.List;

#include "SQLDescribeStatement.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../SQLName.h"

SQLDescribeStatement::SQLDescribeStatement()
{
  partition = std::make_shared<std::list<SQLExpr_ptr>>();
}

SQLName_ptr SQLDescribeStatement::getObject()
{
  return object;
}

void SQLDescribeStatement::setObject(SQLName_ptr object)
{
  this->object = object;
}

SQLName_ptr SQLDescribeStatement::getColumn()
{
  return column;
}

void SQLDescribeStatement::setColumn(SQLName_ptr column)
{
  if (column != nullptr)
  {
    column->setParent(SharedObject(SQLDescribeStatement));
  }
  this->column = column;
}

SQLExpr_list_ptr SQLDescribeStatement::getPartition()
{
  return partition;
}

void SQLDescribeStatement::setPartition(SQLExpr_list_ptr partition)
{
  this->partition = partition;
}

SQLObjectType_ptr SQLDescribeStatement::getObjectType()
{
  return objectType;
}

void SQLDescribeStatement::setObjectType(SQLObjectType_ptr objectType)
{
  this->objectType = objectType;
}

BOOL_ptr SQLDescribeStatement::isExtended()
{
  return extended;
}

void SQLDescribeStatement::setExtended(BOOL_ptr extended)
{
  this->extended = extended;
}

BOOL_ptr SQLDescribeStatement::isFormatted()
{
  return formatted;
}

void SQLDescribeStatement::setFormatted(BOOL_ptr formatted)
{
  this->formatted = formatted;
}

// @Override
void SQLDescribeStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLDescribeStatement)))
  {
    acceptChild(visitor, object);
    acceptChild(visitor, column);
  }
  visitor->endVisit(SharedObject(SQLDescribeStatement));
}

// @Override
SQLObject_list_ptr SQLDescribeStatement::getChildren()
{
  SQLObject_list_ptr tmp = std::make_shared<std::list<SQLObject_ptr>>();
  tmp->push_back(this->object);
  tmp->push_back(column);
  return tmp;
}

BOOL_ptr SQLDescribeStatement::replace(SQLExpr_ptr expr, SQLExpr_ptr target)
{
  if (object == expr)
  {
    setObject(std::dynamic_pointer_cast<SQLName>(target));
    return BOOL::TRUE;
  }

  if (column == expr)
  {
    setColumn(std::dynamic_pointer_cast<SQLName>(target));
    return BOOL::TRUE;
  }

  return BOOL::FALSE;
}
